package cn.edu.ctbu.dp07.service.impl;

import cn.edu.ctbu.dp07.dao.ScoreDao;
import cn.edu.ctbu.dp07.entity.Course;
import cn.edu.ctbu.dp07.entity.Score;
import cn.edu.ctbu.dp07.entity.Student;
import cn.edu.ctbu.dp07.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public  class ScoreServiceImpl implements ScoreService {

    @Autowired
    private ScoreDao scoreDao;
    
    @Override
    public List<Score> findAll() {
        return scoreDao.findAll();
    }
    
    @Override
    public Score findById(Integer id) {
        return scoreDao.findById(id).orElse(null);
    }
    
    @Override
    public List<Score> findByStudent(Student student) {
        return scoreDao.findByStudent(student);
    }
    
    @Override
    public List<Score> findByCourse(Course course) {
        return scoreDao.findByCourse(course);
    }
    
    @Override
    public Score findByStudentAndCourse(Student student, Course course) {
        return scoreDao.findByStudentAndCourse(student, course);
    }
    
    @Override
    public List<Score> findBySemester(String semester) {
        return scoreDao.findBySemester(semester);
    }
    
    @Override
    public Double getAverageScoreByStudent(Student student) {
        return scoreDao.getAverageScoreByStudent(student);
    }
    
    @Override
    public Double getAverageScoreByCourse(Course course) {
        return scoreDao.getAverageScoreByCourse(course);
    }
    
    @Override
    public Score save(Score score) {
        return scoreDao.save(score);
    }
    
    @Override
    public void deleteById(Integer id) {
        scoreDao.deleteById(id);
    }

    public List<Score> findByStudentId(Integer studentId) {
        return scoreDao.findByStudentId(studentId);
    }

    public List<Score> findByCourseId(Integer courseId) {
        return scoreDao.findByCourseId(courseId);
    }

    public Score findByStudentIdAndCourseId(Integer studentId, Integer courseId) {
        return scoreDao.findByStudentIdAndCourseId(studentId, courseId);
    }
} 